<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/static/lib/layui-v2.6.3/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/static/lib/layui-v2.6.3/layui.js}"></script>
    <script type="text/javascript" th:src="@{/static/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/js/jquery-1.9.1.min.js}"></script>
</head>
<body>
<form action="query" method="post">
    <button id="que" type="submit" style="display:none">隐藏的查询按钮</button>
</form>
<form id="ffff" action="query" method="post" class="layui-form">
    <div class="layui-form-item" style="display: inline-block;width: 300px;">
        <label class="layui-form-label">订单号查询:</label>
        <div class="layui-input-block">
            <input type="text" name="orderNo" placeholder="商品名查询" th:value="${order.orderNo}"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item"
         style="display: inline-block; margin-top: 10px; position: relative; left: -20px; width: 300px;">
        <label class="layui-form-label">分类查询:</label>
        <div class="layui-input-block">
            <select name="orderStatus" lay-verify="required">
                <option value="">订单状态</option>
                <option value="1" th:selected="${order.orderStatus eq 1}">待付款</option>
                <option value="2" th:selected="${order.orderStatus eq 2}">待发货</option>
                <option value="3" th:selected="${order.orderStatus eq 3}">已发货</option>
                <option value="4" th:selected="${order.orderStatus eq 4}">已签收</option>
                <option value="5" th:selected="${order.orderStatus eq 5}">退款中</option>
                <option value="6" th:selected="${order.orderStatus eq 6}">已退款</option>
                <option value="7" th:selected="${order.orderStatus eq 7}">交易关闭</option>

            </select>
        </div>
    </div>
    <button id="btn1" type="submit" class="layui-btn" style="display: inline-block; left: 10px;">查询</button>
</form>
<button onclick="getAllChecked()" th:if="${order.orderStatus eq 2}" type="button" class="layui-btn layui-btn-primary"
        style="display: inline-block; left: 10px;">一键发货</button>
<button onclick="getAllChecked()" th:if="${order.orderStatus eq 5}" type="button" class="layui-btn layui-btn-primary"
        style="display: inline-block; left: 10px;">一键退款</button>

<table class="layui-table">
    <thead>
    <tr>
        <th>
            <input type="checkbox" onclick="checkAll(this)">
        </th>
        <th style="font-weight:bolder;">订单号</th>
        <th style="font-weight:bolder;">用户ID</th>
        <th style="font-weight:bolder;">交易金额</th>
        <th style="font-weight:bolder;">交易时间</th>
        <th style="font-weight:bolder;">订单状态</th>
        <th style="font-weight:bolder;">订单详情</th>
    </tr>
    </thead>
    <tbody>
    <span th:each="order:${pageInfo.list}">
					<tr>
						<td>
							<input type="checkbox" th:value="${order.orderNo}" name="k">
						</td>
						<td th:text="${order.orderNo}"></td>
						<td th:text="${order.userId}"></td>
						<td th:text="${order.orderMoney}"></td>
						<td th:text="${order.createTime}"></td>
                        <td th:if="${order.orderStatus eq 1}">待付款</td>
                        <td th:if="${order.orderStatus eq 2}"style="color:#0000FF" >待发货</td>
                        <td th:if="${order.orderStatus eq 3}">已发货</td>
                        <td th:if="${order.orderStatus eq 4}">已签收</td>
                        <td th:if="${order.orderStatus eq 5}" style="color:red">退款中</td>
                        <td th:if="${order.orderStatus eq 6}">已退款</td>
                        <td th:if="${order.orderStatus eq 7}">交易结束</td>
						<td>
                        <button th:onclick="detail([[${order.orderNo}]])" class="layui-btn layui-btn-xs">查看</button>
						</td>
					</tr>
				</span>
    </tbody>
</table>
<div style="text-align:center;">
    <button class="layui-btn" onclick="jump(1)">首页</button>
    <button class="layui-btn" th:onclick="jump([[${pageInfo.pageNum-1}]])">上一页</button>
    <span th:text="${pageInfo.pageNum} + '/' + ${pageInfo.pages} + '页'"></span>
    <button class="layui-btn" th:onclick="jump([[${pageInfo.pageNum+1}]])">下一页</button>
    <button class="layui-btn" th:onclick="jump([[${pageInfo.pages}]])">尾页</button>
</div>
</body>
<script>
		if ([[${pageInfo.pages}]] == 0) {
			alert("没有找到！");
			$("#que").click();
		}

		function jump(pageNum) {
			var params = $("#ffff").serialize();
			var url = "query?" + params + "&pageNum=" + pageNum;
			window.location.href = url;
		}

		//全选中或不选中
		function checkAll(obj) {
			var a = $(obj).prop("checked"); //true 和 false
			if (a) {
				$(":checkbox[name='k']").prop("checked", true);
			} else {
				$(":checkbox[name='k']").prop("checked", false);
			}
		}
		//一键退款
		function getAllChecked() {
			var es = $(":checkbox[name='k']:checked");
			var params = "";
			$.each(es, function(index, item) {
				console.info(item.value);
				params += item.value + ",";
			})
			if (params.length == 0) {
				alert("请选中下架商品！");
				$("#btn1").click();
			} else {
				window.location.href = "shipments?ids=" + params.substr(0, params.length - 1);
				alert("退款成功！");

			}
		}
		function detail(orderNo){
    window.location.href="detail?orderNo="+orderNo;
		}


	</script>

</html>
